#!/bin/bash

SUPPORTED_EXTENSIONS=("c" "cpp" "cc" "h" "hpp")

echo "当前工作目录: $(pwd)"
echo "正在搜索的文件类型: ${SUPPORTED_EXTENSIONS[*]}"

FIND_CMD="find . -type f"
for ext in "${SUPPORTED_EXTENSIONS[@]}"; do
    FIND_CMD+=" -o -name '*.$ext'"
done
FIND_CMD="${FIND_CMD/-o /}"
FILES=$(eval "$FIND_CMD")

FILE_COUNT=$(echo "$FILES" | wc -l | tr -d ' ')
echo "找到 $FILE_COUNT 个匹配文件:"
echo "$FILES"
echo "------------------------"

echo "开始格式化文件..."
for FILE in $FILES; do
    echo "格式化: $FILE"
    clang-format -i --style=file "$FILE"
done

echo "格式化完成！共处理 $FILE_COUNT 个文件"
exit 0